/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package smartgrid;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

import java.io.Serializable;
public class DiaAgregado implements Serializable {
	public DiaAgregado() {
	}
	
	public static DiaAgregado loadDiaAgregadoByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadDiaAgregadoByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado getDiaAgregadoByORMID(int ID) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getDiaAgregadoByORMID(session, ID);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado loadDiaAgregadoByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadDiaAgregadoByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado getDiaAgregadoByORMID(int ID, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return getDiaAgregadoByORMID(session, ID, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado loadDiaAgregadoByORMID(PersistentSession session, int ID) {
		try {
			return (DiaAgregado) session.load(smartgrid.DiaAgregado.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado getDiaAgregadoByORMID(PersistentSession session, int ID) {
		try {
			return (DiaAgregado) session.get(smartgrid.DiaAgregado.class, new Integer(ID));
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado loadDiaAgregadoByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (DiaAgregado) session.load(smartgrid.DiaAgregado.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado getDiaAgregadoByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) {
		try {
			return (DiaAgregado) session.get(smartgrid.DiaAgregado.class, new Integer(ID), lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado[] listDiaAgregadoByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listDiaAgregadoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado[] listDiaAgregadoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return listDiaAgregadoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado[] listDiaAgregadoByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.DiaAgregado as DiaAgregado");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (DiaAgregado[]) list.toArray(new DiaAgregado[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado[] listDiaAgregadoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.DiaAgregado as DiaAgregado");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (DiaAgregado[]) list.toArray(new DiaAgregado[list.size()]);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado loadDiaAgregadoByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadDiaAgregadoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado loadDiaAgregadoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return loadDiaAgregadoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado loadDiaAgregadoByQuery(PersistentSession session, String condition, String orderBy) {
		DiaAgregado[] diaAgregados = listDiaAgregadoByQuery(session, condition, orderBy);
		if (diaAgregados != null && diaAgregados.length > 0)
			return diaAgregados[0];
		else
			return null;
	}
	
	public static DiaAgregado loadDiaAgregadoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		DiaAgregado[] diaAgregados = listDiaAgregadoByQuery(session, condition, orderBy, lockMode);
		if (diaAgregados != null && diaAgregados.length > 0)
			return diaAgregados[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateDiaAgregadoByQuery(String condition, String orderBy) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iterateDiaAgregadoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateDiaAgregadoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) {
		try {
			PersistentSession session = smartgrid.SmartgridPersistentManager.instance().getSession();
			return iterateDiaAgregadoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateDiaAgregadoByQuery(PersistentSession session, String condition, String orderBy) {
		StringBuffer sb = new StringBuffer("From smartgrid.DiaAgregado as DiaAgregado");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static java.util.Iterator iterateDiaAgregadoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) {
		StringBuffer sb = new StringBuffer("From smartgrid.DiaAgregado as DiaAgregado");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			return null;
		}
	}
	
	public static DiaAgregado loadDiaAgregadoByCriteria(DiaAgregadoCriteria diaAgregadoCriteria) {
		DiaAgregado[] diaAgregados = listDiaAgregadoByCriteria(diaAgregadoCriteria);
		if(diaAgregados == null || diaAgregados.length == 0) {
			return null;
		}
		return diaAgregados[0];
	}
	
	public static DiaAgregado[] listDiaAgregadoByCriteria(DiaAgregadoCriteria diaAgregadoCriteria) {
		return diaAgregadoCriteria.listDiaAgregado();
	}
	
	public static DiaAgregado createDiaAgregado() {
		return new smartgrid.DiaAgregado();
	}
	
	public boolean save() {
		try {
			smartgrid.SmartgridPersistentManager.instance().saveObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean delete() {
		try {
			smartgrid.SmartgridPersistentManager.instance().deleteObject(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean refresh() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().refresh(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean evict() {
		try {
			smartgrid.SmartgridPersistentManager.instance().getSession().evict(this);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate() {
		try {
			if(getContract() != null) {
				getContract().diaAgregados.remove(this);
			}
			
			return delete();
		}
		catch(Exception e) {
			return false;
		}
	}
	
	public boolean deleteAndDissociate(org.orm.PersistentSession session) {
		try {
			if(getContract() != null) {
				getContract().diaAgregados.remove(this);
			}
			
			try {
				session.delete(this);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			return false;
		}
	}
	
	private void this_setOwner(Object owner, int key) {
		if (key == smartgrid.ORMConstants.KEY_DIAAGREGADO_CONTRACT) {
			this.contract = (smartgrid.Contract) owner;
		}
	}
	
	org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {
		public void setOwner(Object owner, int key) {
			this_setOwner(owner, key);
		}
		
	};
	
	private int ID;
	
	private smartgrid.Contract contract;
	
	private double gastoSUM;
	
	private String unidade;
	
	private double precoSUM;
	
	private java.util.Date data;
	
	private double gastoAVG;
	
	private double precoAVG;
	
	private void setID(int value) {
		this.ID = value;
	}
	
	public int getID() {
		return ID;
	}
	
	public int getORMID() {
		return getID();
	}
	
	public void setGastoSUM(double value) {
		this.gastoSUM = value;
	}
	
	public double getGastoSUM() {
		return gastoSUM;
	}
	
	public void setGastoAVG(double value) {
		this.gastoAVG = value;
	}
	
	public double getGastoAVG() {
		return gastoAVG;
	}
	
	public void setUnidade(String value) {
		this.unidade = value;
	}
	
	public String getUnidade() {
		return unidade;
	}
	
	public void setPrecoSUM(double value) {
		this.precoSUM = value;
	}
	
	public double getPrecoSUM() {
		return precoSUM;
	}
	
	public void setPrecoAVG(double value) {
		this.precoAVG = value;
	}
	
	public double getPrecoAVG() {
		return precoAVG;
	}
	
	public void setData(java.util.Date value) {
		this.data = value;
	}
	
	public java.util.Date getData() {
		return data;
	}
	
	public void setContract(smartgrid.Contract value) {
		if (contract != null) {
			contract.diaAgregados.remove(this);
		}
		if (value != null) {
			value.diaAgregados.add(this);
		}
	}
	
	public smartgrid.Contract getContract() {
		return contract;
	}
	
	/**
	 * This method is for internal use only.
	 */
	private void setORM_Contract(smartgrid.Contract value) {
		this.contract = value;
	}
	
	private smartgrid.Contract getORM_Contract() {
		return contract;
	}
	
	public String toString() {
		return String.valueOf(getID());
	}
	
}
